package com.samxcode.leetcode;

public class Sort {

    public static void main(String[] args) {
        int[] numbers = { 1, 4, 6, 7, 9, 2, 45, 23 };
        insertSort(numbers);
        for (int i : numbers) {
            System.out.println(i + " ");
        }
    }


    public static int[] insertSort(int[] numbers) {
        for (int i = 1; i < numbers.length; i++) {
            int temp = numbers[i];
            int j = i - 1;
            while (j >= 0 && numbers[j] > temp) {
                numbers[j + 1] = numbers[j];
                j--;
            }
            numbers[j + 1] = temp;
        }
        return numbers;
    }
}
